package tcln.gxtx.client.utils;

import com.extjs.gxt.ui.client.state.Provider;

/**
 * An abstract provider which provides more control for the management of components' state. Control extensions are:
 * <ul>
 * <li>Enable/disable updating via {@link #set(String, Object)} and {@link #clear(String)}.
 * </ul>
 * 
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
public abstract class AbstractProvider extends Provider {

    /**
     * A flag indicating if updating on this provider should be disabled or not.
     */
    private boolean updatingDisabled;

    /**
     * Returns current value of updatingDisabled.
     * 
     * @return the updatingDisabled.
     */
    public boolean isUpdatingDisabled() {
        return updatingDisabled;
    }

    /**
     * Sets new value for updatingDisabled.
     * 
     * @param updatingDisabled
     *            the updatingDisabled to set.
     */
    public void setUpdatingDisabled(boolean updatingDisabled) {
        this.updatingDisabled = updatingDisabled;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void set(String name, Object value) {
        if (!updatingDisabled) {
            super.set(name, value);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void clear(String name) {
        if (!updatingDisabled) {
            super.clear(name);
        }
    }
}
